{extend name="public/base" /}
{block name="style"}
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/index.css?v=20221110&times=111" />
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/iconfont.css" />
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_3754223_a1vp94akoxt.css">
{include file="material/_ali_icon" /}
<link href="/public/plugs/datepicker/css/foundation-datepicker.min.css" rel="stylesheet" type="text/css">

<style>
.main-box-body .navs .active {
        background: azure;
        color: #03a9f4;
        border: 1px solid #03a9f4;
        border-radius: 5px;
    }
.table tbody>tr>td {padding: 0px 8px;}
.table-hover>tbody>tr:nth-child(odd){background-color: #f9f9f9;}
.table-responsive {
    min-height: 470px;
}
.toolTip{
	display: flex;
	height:42px;
	align-items: center;
}
.toolTip .num{
	font-size: 13px;
	margin-right: 5px;
	color:#9b2805
}
.title{
	font-weight: bold;
	color: #d50000;
	font-size:14px!important;
	letter-spacing: 1px;
}
.status .iconfont{
	vertical-align: middle;
}
em{
	color: red;
}
a {
		color: #777;
		text-decoration:none;
	}
</style>
{/block}
{block name="body"}
<div class="main-box clearfix">
	<header class="main-box-header clearfix">
		<div class="pull-right">
			<!-- <button type="button" class="btn btn-primary" id="createUrl">
				<i class="fa fa-plus"></i> 添加素材 <span class="caret"></span>
			</button> -->
			{if checkAuthRule('del')}<button id="checkALL" type="button" class="btn btn-warning"> <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;"> 全选 </button>{/if}
			<button type="button" class="btn btn-success " id="lower">
				下放 
			</button>
			{if checkAuthRule('txt')}<button style="margin-right:5px" class="btn btn-primary download" >下载TXT</button>{/if}


			{if checkAuthRule('down_all')}<button type="button" class="btn btn-info" onclick="down_all('{:url('down_all',['source' => 'mycenter'])}')">
				<i class="fa fa-cloud-download"></i> 全库TXT 
			</button>{/if}
			
			<button class="btn btn-info allCopy" >复制</button>
			{if checkAuthRule('del')}<button class="btn btn-danger ajax-post confirm" url="{:url('del_my')}" target-form="ids">删 除</button>{/if}
		</div>
		<div class="row">
			<form method="get">
				
				{include file="material/_search2" /}
			</form>
		</div>
	</header>
	<div class="main-box-body clearfix">
		<!-- 搜索相关 -->
		{include file="material/_search" /}
		<div id="" class="clear"></div>
		<div class="table-responsive clearfix">
			<div class="table-responsive clearfix">
				<table class="table table-hover table-bordered">
					<thead>
						<tr>
							<th width="50px"><input class="checkbox check-all" type="checkbox" style="display:inline"></th>
							{include file="material/_book_sort" /}
							<th width="50%">文案</th>
							{if checkAuthRule('user')}<th width="80px">工号</th>{/if}
							<!-- 达标 -->
							{include file="material/_status_sort" /}
							{include file="material/_time_sort" /}
							<th width="80px">复制文案</th>
							
							<th width="80px">公众库</th>
							<!-- <th>热度/平台/频道/分类/工号</th> -->
							<!-- <th width="10%">标签</th> -->
							<th width="130px">操作</th>
						</tr>
					</thead>
					<tbody>
						{empty name="list"}
						<tr><td colspan="9" align="center">暂无数据</td></tr>
						{/empty}
						{volist name="list" id="vo"}
						<tr>
							<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$vo['id']}"></td>
							<td class="title">{$vo.book_id_zh}</td>
							
							<td class="toolTip">
								<div class="num">
									{$vo.num}
								</div>
								<div class="example" style='font-size: 18px; -webkit-line-clamp: 1; color: rgba(33, 33, 33, 0.66);' title2="{$vo.content}">
									{$vo.content_zh}
								</div>
							</td>
							{if checkAuthRule('user')}
							<td>
								{if $vo['is_distribution'] == 1}
								<span style="color: #e84e40;">{$userlist[$vo['uid']]??$vo['uid']}</span>
								{else/}
								{$userlist[$vo['uid']]??$vo['uid']}
								{/if}
							</td>
							{/if}
							<td class="status" onclick="change_status({$vo.id})">
								{if $vo['status'] == 0}
								<span class="iconfont icon-tongguo"></span>
								过稿
								{else/}
								<span style="color: #eb3939;">
								<span class="iconfont icon-tongguo"></span>
								已过稿</span>
								{/if}
							</td>
							<td>{$vo['show_time']}</td>
							<td>
								<div onclick="copyContent(`{$vo.content_zh}`, '{$vo.id}')" class="copy">
									<span class="iconfont icon-copy"></span>
									复制
								</div>
							</td>
							
							<td>
								<div onclick="upload(this, {$vo['id']})" id="upload_id_{$vo['id']}" class="copy" data-json='{:json_encode($vo)}'>
									{if $vo['is_upload']}
									&nbsp;<span style="color: #eb3939;">已上报</span>
									{else/}
									<span class="fa fa-plus"></span>
									&nbsp;上报
									{/if}
									
								</div>
							</td>
							
							<!-- <td>{$vo.hot_zh} / {$vo.platform_ids_zh} / {$vo.channel_zh} / {$vo.category_id_zh} | {$userlist[$vo['uid']]??$vo['uid']} </td> -->
							<!-- <td>{$vo.tag_ids_zh}</td> -->
							
							
							<td>
								{if checkAuthRule('del')}<a href="{:url('del_my',array('id'=>$vo['id']))}" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>{/if}
								<a href="JavaScript:;" onclick="editreferral(this)" data-json='{:json_encode($vo)}'><i class="fa fa-edit"></i> 修改</a>
							</td>
							
						</tr>
						{/volist}
						
					</tbody>
				</table>
			</div>
			{$page}
		</div>
	</div>
</div>

<div class="modal fade" id="create-referral-link-modal">
	<div class="modal-dialog" role="document">
	   <div class="modal-content">
		   <div class="modal-header">
			   <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
			   <span style="font-size: 20px;"><span id="referralname">添加</span></span>
		   </div>
		   <div class="modal-body">
			   <div data-bind="visible: loading" class="loading-panel" style="display: none;">
				   <i class="fa fa-spin fa-spinner"></i>
			   </div>
			   <form class="form-horizontal modelform">
				   {include file="material/_from" /}
			   </form>
		   </div>
		   <div class="modal-footer">
			   <button type="button" id="createreferral" class="btn btn-primary ">提交</button>
		   </div>
	   </div>
   </div>
</div>

{include file="adsmaterialbook/_from" /}
{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
<script type="text/javascript">
function follow(ee, id){
	var url = "{:url('addFollow')}";
	$.ajax({
		type: "POST",
		url: url,
		data:{id:id},
		dataType: "json",
		success: function(data){
			if(data.code==1){
				layer.msg(data.msg);
				setTimeout(function() {	
					window.location.reload();
				}, 1500);
			}else{
				updateAlert("失败，"+data.msg, 'danger');
			}
		},
		error : function(e){
			console.log(e.status);
			console.log(e.responseText);
		}
	})
}

$(function() {
	$("#createreferral").on('click',function(){
		var data = data2 = $('.modelform').serializeJson();
		console.log(data);
		if (data['content'].length==0) {
			updateAlert("不能为空", 'danger');
			return false;
		}
		var url = "{:url('add_my')}";
		$.ajax({
			type: "POST",
			url: url,
			data:data,
			dataType: "json",
			success: function(data){
				if(data.code==1){
					updateAlert(data.msg, 'success');
					if(data2['id'] == $('body').attr("upload_id")){
						upload($("#upload_id_"+data2['id']), data2['id']);
					}
					setTimeout(function() {	
						window.location.reload();
					}, 100);
				}else{
					updateAlert(""+data.msg, 'danger');
				}
			},
			error : function(e){
				console.log(e.status);
				console.log(e.responseText);
			}
		})
	});
});

	$('#startdata').fdatepicker({
		format: 'yyyy-mm-dd',
		// pickTime: true
	});
	$('#enddata').fdatepicker({
		format: 'yyyy-mm-dd',
		// pickTime: true
	});
	// 下载txt
	let downloadUrl_request = "{:url('down_txt')}?platform_ids={$platform_id}&type={$type}"
	let downloadUrl = ''
	$('.check-all').change(function(){
		let template = '';
		$('input[name="id[]"]:checked').each(function(index, element) {
			template += '&id[]='+$(element).val()
		});
		downloadUrl = downloadUrl_request+template
	})
	$('.row-selected').change(function(){
		let template = '';
		$('input[name="id[]"]:checked').each(function(index, element) {
			template += '&id[]='+$(element).val()
		});
		downloadUrl = downloadUrl_request+template
	})
	$('.download').click(function(){
		if(downloadUrl){
			var $a = document.createElement('a');
			$a.setAttribute("href", downloadUrl);
			$a.setAttribute("download", "");
			var evObj = document.createEvent('MouseEvents');
			evObj.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
			$a.dispatchEvent(evObj);
		}else{
			layer.msg('请选择文案',{icon:5,time:2000});
		}
	})
	// 批量复制
	$('.allCopy').click(function(){
		let template = ''
		$('input[name="id[]"]:checked').each(function(index, element) {
			template += $(element).parent().siblings('.toolTip').children('.example').text().trim() + '\r\n'
			var oInput = document.createElement('textarea');//
			oInput.value = template;
			document.body.appendChild(oInput);
			oInput.select();
			document.execCommand("Copy");
			oInput.className = 'oInput';
			oInput.style.display='none';
			layer.msg('复制成功');
		});
	})
	
</script>

{include file="material/pub_footer"}
{/block}